package org.bspv.pharma.business.impl;

import java.util.ArrayList;
import java.util.List;

import org.bspv.pharma.business.InventoryTrackingBusinessService;
import org.bspv.pharma.manager.ConsumableManager;
import org.bspv.pharma.manager.PlaceManager;
import org.bspv.pharma.manager.StandardEquipmentDetailManager;
import org.bspv.pharma.manager.StandardEquipmentManager;
import org.bspv.pharma.manager.SupplyManager;
import org.bspv.pharma.model.Consumable;
import org.bspv.pharma.model.Place;
import org.bspv.pharma.model.StandardEquipment;
import org.bspv.pharma.model.StandardEquipmentDetail;
import org.bspv.pharma.model.Supply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @author guillaume
 *
 */
@Service(value = "inventoryTrackingBusinessService")
public class InventoryTrackingBusinessServiceImpl implements InventoryTrackingBusinessService {

    /**
     * Service basique pour les emplacements.
     */
    @Autowired
    private PlaceManager placeManager;
    /**
     * Service basique pour les fournitures.
     */
    @Autowired
    private SupplyManager supplyManager;
    /**
     * Service basique pour les consommables.
     */
    @Autowired
    private ConsumableManager consumableManager;
    /**
     * Service basique pour les equipements standards.
     */
    @Autowired
    private StandardEquipmentManager standardEquipmentManager;
    /**
     * Service basique pour les détails d'équipements standards.
     */
    @Autowired
    private StandardEquipmentDetailManager standardEquipmentDetailManager;

    /**
     * {@inheritDoc}
     */
    public List<Supply> findAllSupplies(Place place) {
      //Recupération de l'ensemble des sous emplacements
        List<Place> places = placeManager.findAllValidChildren(place);
        places.add(place);
        // recuperation des fournitures pour l'emplacement et ses sous-emplacements
        return supplyManager.findSupplies(places);
    }

    
    /**
     * {@inheritDoc}
     */
    public List<Consumable> findAllConsumables(Place place) {
        //Recupération de l'ensemble des sous emplacements
        List<Place> places = placeManager.findAllValidChildren(place);
        places.add(place);
        // recuperation des consommables pour l'emplacement et ses sous-emplacements
        return consumableManager.findConsumables(places);
    }

    
    /**
     * {@inheritDoc}
     */
    public List<Place> findSubPlaces(Place place) {
        return placeManager.findValidChildren(place);
    }
    
    
    /**
     * {@inheritDoc}
     */
    public List<Consumable> findConsumables(Place place) {
        List<Consumable> results = new ArrayList<Consumable>();
        // recuperation des fournitures pour l'emplacement
        results.addAll(consumableManager.findConsumables(place));
        return results;
    }
    
    
    /**
     * {@inheritDoc}
     */
    public List<Supply> findSupplies(Place place) {
        List<Supply> results = new ArrayList<Supply>();
        // recuperation des fournitures pour l'emplacement
        results.addAll(supplyManager.findSupplies(place));
        return results;
    }

    
    /**
     * {@inheritDoc}
     */
    public StandardEquipment findStandardEquipmentFromPlace(Place place) {
        return standardEquipmentManager.findStandardEquipment(place);
    }

    
    /**
     * {@inheritDoc}
     */
    public List<StandardEquipmentDetail> findAllStandardEquipmentDetails(Place place) {
        return standardEquipmentDetailManager.findAllStandardEquipmentDetails(place);
    }
    
    
    // ACCESSEURS
    
    /**
     * @param placeManager
     *            the placeManager to set
     */
    public void setPlaceManager(PlaceManager placeManager) {
        this.placeManager = placeManager;
    }

    /**
     * @param supplyManager
     *            the supplyManager to set
     */
    public void setSupplyManager(SupplyManager supplyManager) {
        this.supplyManager = supplyManager;
    }

    /**
     * @param consumableManager
     *            the consumableManager to set
     */
    public void setConsumableManager(ConsumableManager consumableManager) {
        this.consumableManager = consumableManager;
    }

    /**
     * @param standardEquipmentManager
     *            the standardEquipmentManager to set
     */
    public void setStandardEquipmentManager(StandardEquipmentManager standardEquipmentManager) {
        this.standardEquipmentManager = standardEquipmentManager;
    }

    /**
     * @param standardEquipmentDetailManager
     *            the standardEquipmentDetailManager to set
     */
    public void setStandardEquipmentDetailManager(StandardEquipmentDetailManager standardEquipmentDetailManager) {
        this.standardEquipmentDetailManager = standardEquipmentDetailManager;
    }

}
